#!/usr/bin/python
# -*- coding: utf-8 -*-
import os
import sys
import time
from engine.common import *
if sys.platform == "darwin":
    adbpath = "adb "
else:
    adbpath = "/usr/bin/adb "
if (sys.argv.__len__())<4:
    print( "参数个数少了")
    exit(0)
handset = sys.argv[1]
currentHandsetSnumber = sys.argv[2]
command = sys.argv[3]
resultF = sys.argv[4]

filePath = sys.argv[5]



def ReadMsg( handset,currentHandsetSnumber,resultF,filePath="./temp/curl.txt",delay=5 ):
    setHandsetType(handset)
    setHandsetSno(currentHandsetSnumber)
    posx=""
    if os.path.exists(getHandsetFileSavePath("./temp/posx_error.txt")):
        with open(getHandsetFileSavePath("./temp/posx_error.txt") )as f:
            posx = f.read()


    with open(getHandsetFileSavePath(filePath)) as f:
        print('open this file')
        listText = f.read()
    listText = eval(listText)
    msg = ""
    lastMsg = ""
    for rectFocus in listText:
        if rectFocus[2] > 0.99:
            if rectFocus[0][1] > 40 :
                msg = msg+ rectFocus[1]+"[nr]"
                lastMsg = rectFocus[1]

    msg = msg.replace(' ','[s]')
    msg = msg.replace('(', '{[')
    msg = msg.replace(')', ']}')

    if "视频" in lastMsg:
        debugInfo("客户可能要视频啊你回复下吧")
        print(lastMsg)
        print("客户可能要视频啊 -------------")



    print(msg)
    getAndSetMsgFromHandsetCliper(msg,currentHandsetSnumber)
    with open(getHandsetFileSavePath(resultF),'w')as f:
        if '-1' in posx:
            f.write('True')
            return True  #TRUE 状态转移
        else:
            f.write('False')
            return False

if command =="ReadMsg".strip():
    ReadMsg(handset,currentHandsetSnumber,resultF,filePath)
